# Contributor: Maxim Karasev <mxkrsv@disroot.org>
# Maintainer: Patrycja Rosa <alpine@ptrcnull.me>
pkgname=r2ghidra
pkgver=5.8.6
_ghidra_native=0.2.5
pkgrel=2
pkgdesc="native ghidra decompiler for radare2"
url="https://github.com/radareorg/r2ghidra"
# this is massive, and nobody is going to use a decompiler on other
# architectures
arch="x86_64 aarch64 ppc64le"
license="LGPL-3.0-only AND Apache-2.0"
depends="radare2"
makedepends="
	libzip-dev
	meson
	openssl-dev
	pugixml-dev
	radare2-dev
	"
source="https://github.com/radareorg/r2ghidra/archive/refs/tags/$pkgver/r2ghidra-$pkgver.tar.gz
	https://github.com/radareorg/ghidra-native/archive/refs/tags/$_ghidra_native/ghidra-native-$_ghidra_native.tar.gz
	use-system-pugixml.patch"
options="!check" # no tests

prepare() {
	default_prepare
	mv "$srcdir"/ghidra-native-"$_ghidra_native" "$builddir"/ghidra-native
	make -C "$builddir"/ghidra-native patch
}

build() {
	abuild-meson \
		-Db_lto=true \
		. output
	meson compile -C output

	# not implemented for meson yet
	cd ghidra
	make sleigh-build
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output

	# not implemented for meson yet
	cd "$builddir"/ghidra
	make D="$pkgdir"/usr/lib/radare2/$pkgver/r2ghidra_sleigh sleigh-install
}

sha512sums="
113fbb70397cf11d84eb1eb23d966b0815cf476b4a7233972597d7e99a4ebae26d5ca74a80eb787542c1e4409e5817251a5f5d7cd13df85a286b469192544071  r2ghidra-5.8.6.tar.gz
f385967d87af85f448f2089b8ca0bd0726b7d0b5398cebdb9cbe08d4344426f40b74fd0a8f7641f598e66a740f7802c7a9011af6a4708920cd837af470586b78  ghidra-native-0.2.5.tar.gz
6616f82b119e59f083b8ef43198effb094a0592a575220b0e40d48b42b4ee5b519a0a0d9e1ed4c9c61968a624625cf0c4a874884e8af334b5006378d7bdd9390  use-system-pugixml.patch
"
